﻿// Copyright 2010 Maxime Serrano <lastchronicler@gmail.com>
// Copyright 2009, 2010 Matvei Stefarov <me@matvei.org>
using System;

namespace ForgeCraft
{
    public class CmdKick : Command
    {
        public override string name { get { return "kick"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "op"; } }
        public override bool consoleUsable { get { return false; } }
        public override Permission defaultRank { get { return Permission.Guest; } }
        public CmdKick() { }

        public override void Use(Player p, string message)
        {
            string name = message;
            if (name != null)
            {
                string msg = message;
                Player offender = Server.FindPlayer(name);
                if (offender != null)
                {
                    Server.SendToAll(Color.Red + offender.nick + " was kicked by " + p.nick);
                    if (msg != null && msg.Length > 0)
                    {
                        Logger.Log("{0} was kicked by {1}. Memo: {2}", LogType.UserActivity, offender.GetLogName(), p.GetLogName(), msg);
                        offender.session.Kick("Kicked by " + p.GetLogName() + ": " + msg);
                    }
                    else
                    {
                        Logger.Log("{0} was kicked by {1}", LogType.UserActivity, offender.GetLogName(), p.GetLogName());
                        offender.session.Kick("You have been kicked by " + p.GetLogName());
                    }
                }
                else
                {
                    p.NoPlayerMessage(name);
                }
            }
            else
            {
                p.Message("Usage: " + Color.Help + "/kick PlayerName [Message]" +
                                   Color.Sys + " or " + Color.Help + "/k PlayerName [Message]");
            }
        }
        public override void Help(Player p)
        {
            p.Message(Color.Aqua + "/kick " + Color.Help + "- Kicks the specified player from the server.");
        }
    }
}